package cn.xiaobai.j2exe;

import cn.xiaobai.j2exe.utils.SourceUtils;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;


public class MainApplication extends Application {

    private final static Logger log = LoggerFactory.getLogger(MainApplication.class);

    private static Stage primaryStage;

    @Override
    public void start(Stage stage) throws IOException {
        primaryStage = stage;
        mainStage();
    }

    private void mainStage() throws IOException {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(SourceUtils.getFxml("main-app.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            primaryStage.setTitle("J2EXE");
            primaryStage.getIcons().add(SourceUtils.getPngImg("logo-40.png"));
            primaryStage.setResizable(false); // 取消最大化
            primaryStage.setScene(scene);
            primaryStage.centerOnScreen(); // 居中显示
            primaryStage.show();
        } catch (Exception e) {
            log.error("load javafx application fail: ", e.fillInStackTrace());
            throw new IOException(e);
        }
    }

    @Override
    public void stop() throws Exception {
        primaryStage.close();
        Platform.exit();
    }
}